CREATE TABLE [dbo].[text_BookTree] (
    [BookTreeId]       BIGINT           IDENTITY (1, 1) NOT NULL,
    [ParentBookTreeId] BIGINT           NULL,
    [LeftKey]          INT              NOT NULL,
    [RightKey]         INT              NOT NULL,
    [Level]            TINYINT          NOT NULL,
    [BookId]           UNIQUEIDENTIFIER NOT NULL,
    [HashTag]          NVARCHAR (128)   NULL,
    [IsHead]           BIT              CONSTRAINT [DF_text_BookTree_IsHead] DEFAULT ((0)) NOT NULL,
    [Text]             NVARCHAR (MAX)   NOT NULL,
    [Published]        BIT              CONSTRAINT [DF_text_BookTree_Published] DEFAULT ((0)) NOT NULL,
    [UpdateDate]       DATETIME         CONSTRAINT [DF_text_BookTree_UpdateDate] DEFAULT (getdate()) NOT NULL,
    [PublishedDate] DATETIME NULL, 
    CONSTRAINT [PK_text_BookTree] PRIMARY KEY CLUSTERED ([BookTreeId] ASC),
    CONSTRAINT [FK_text_BookTree_text_Book] FOREIGN KEY ([BookId]) REFERENCES [dbo].[text_Book] ([BookId])
);








GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_text_BookTree_RightKey]
    ON [dbo].[text_BookTree]([RightKey] ASC, [BookId] ASC);




GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_text_BookTree_LeftKey]
    ON [dbo].[text_BookTree]([LeftKey] ASC, [BookId] ASC);




GO
CREATE NONCLUSTERED INDEX [IX_text_BookTree_Level]
    ON [dbo].[text_BookTree]([Level] ASC);


GO

CREATE NONCLUSTERED INDEX [IX_text_BookTree_HashTag] 
		ON [dbo].[text_BookTree] ([HashTag] ASC)

GO

CREATE NONCLUSTERED INDEX [IX_text_BookTree_BookId] 
		ON [dbo].[text_BookTree] ([BookId] ASC)

GO
CREATE NONCLUSTERED INDEX [IX_text_BookTree_IsHead]
    ON [dbo].[text_BookTree]([IsHead] ASC);

